<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  Netty WebSocket 时间服务器
</head>
<br/>
<body>
<br>
<script type="text/javascript">
  var socket;
  if (!window.WebSocket) {
    window.WebSocket = window.MozWebSocket;
  }
  if (window.WebSocket) {
    socket = new WebSocket("ws://127.0.0.1:30336/connect?token=token");
    socket.onmessage = function (event) {
      console.log("xxx" + event)
      var ta = document.getElementById('responseText');
      ta.value = ta.value + '\n' + event.data;
    };
    socket.onopen = function (event) {
      var ta = document.getElementById('responseText');
      ta.value = "打开WebSocket服务正常，浏览器支持WebSocket!";
    };
    socket.onclose = function (event) {
      var ta = document.getElementById('responseText');
      ta.value = "WebSocket 关闭!";
    }
  } else {
    alert("抱歉，您的浏览器不支持WebSocket协议!");
  }

  function send(message) {
    if (!window.WebSocket) {
      return;
    }
    if (socket.readyState == WebSocket.OPEN) {
      socket.send(message);
    }else {
      alert("WebSocket连接没有建立成功!");
    }
  }
</script>
<form onsubmit="return false;">
  <!--
    LOGIN_URL(1, "登录二维码返回", WsMsgLoginUrl.class),
    LOGIN_SCAN_SUCCESS(2, "用户扫描成功等待授权", null),
    LOGIN_SUCCESS(3, "用户登录成功返回用户信息", WsMsgLoginSuccess.class),

    INVALIDATE_TOKEN(4, "使前端的token失效，意味着前端需要重新登录", null),
    HEAR_BEAT(6, "心跳反应", null),
    USER_ACCOUNT_CHANGE(7, "用户账户变动", null),
    SYSTEM_MESSAGE_NOTIFICATION(100, "系统消息通知", null),
    IMPORT_DISPOSE_RESULT(101, "导入数据处理结果返回", null),
    EXPORT_DISPOSE_RESULT(102, "导出处理结果返回", null),
    -->
  <input type="text" name="message" value="{'type':1}">
  <br/><br/>
  <input type="button" value="发送WebSocket请求消息" onclick="send(this.form.message.value)">
  <hr color="blue"/>
  <h3>服务端返回的应答消息</h3>
  <textarea id="responseText" style="width:500px; height: 300px;"></textarea>
</form>
</body>
</html>
